<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of TeamController
 *
 * @author Admin
 */
class Marketing_TeamController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function preDispatch() {
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            $this->_redirect('/user/login');
        }

        $view = new Zend_View();
        $view->headTitle(' > Marketing > Team');
        $this->view->userDetail = $auth->getIdentity();
    }

    public function indexAction() {
        $switchUsersModel = new Application_Model_SwitchUserModel();
        $paginator = $switchUsersModel->getAllSwitchUserNamesForMarketing($this->_request);
        $this->view->paginator = $paginator;
    }

    public function listAction() {
        $this->_helper->layout->disableLayout();
        $switchUsersModel = new Application_Model_SwitchUserModel();
        $paginator = $switchUsersModel->getAllSwitchUserNamesForMarketing($this->_request);
        $this->view->paginator = $paginator;
    }

    public function addAction() {
        $this->_helper->layout->disableLayout();
        $form = new Application_Form_team_AddForm();

        // if request is post
        if ($this->_request->isPost()) {
            // if form is valid
            if ($form->isValid($this->_request->getPost())) {
                $data = array(
                    'name' => $this->_request->getPost('cabinetName'),
                    'status' => $this->_request->getPost('status')
                );
                $teamModel->save($data);
                //   $this->_redirect("planning/cabinet");
                //  exit;
            }
        }
        // assign form variable to view
        $this->view->form = $form;
    }

    public function editAction() {
        $this->_helper->layout->disableLayout();
        $form = new Application_Form_team_AddForm();
        // if request is post
        if ($this->_request->isPost()) {
            // if form is valid
            if ($form->isValid($this->_request->getPost())) {
                $data = array(
                    'name' => $this->_request->getPost('cabinetName'),
                    'status' => $this->_request->getPost('status')
                );
                $teamModel->save($data);
                //   $this->_redirect("planning/cabinet");
                //  exit;
            }
        }
        // assign form variable to view
        $this->view->form = $form;
    }
    
    public function userhouseAction(){
        $userId = $this->_request->getParam('id');
        $houseModel = new Application_Model_HouseModel();
        $paginator = $houseModel->getAllUserAssignedSwitcheHousesForMarketing($this->_request, $userId);
        $this->view->paginator = $paginator;
    }
    
    public function interactionAction() {
        $this->_helper->layout->disableLayout();
        $houseModel = new Application_Model_HouseModel();

        $id = $this->_request->getParam('id');
        $interaction = $houseModel->getHouseDetail($id);
        $this->view->interaction = $interaction;
        $this->view->houseId = $id;
    }
    
    public function contractAction() {
        $this->_helper->layout->disableLayout();
        $id = $this->_request->getParam('id');
        $this->view->houseId = $id;
    }
}